<template>
    <div>
        <!-- 顶部滑动条 -->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0? 'mui-active' : '']" v-for="item in category" :key="item.id" @click="getPhotoList(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>

        </div>

        <!-- 图片列表区域 -->
        <ul class="photoList">
            <router-link v-for="item in photoList" :key="item.id" :to="`/home/photoInfo/${item.id}`" tag="li">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="title">{{item.title}}</h1>
                    <h2 class="body">{{item.zhaiyao}}</h2>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    export default {
        name: "PhotoList",
        data() {
            return {
                category: [],
                photoList: []
            }
        },
        created() {
            this.getAllCategory();
            this.getPhotoList(0);
        },
        methods: {
            getAllCategory() {
                //获取所有分类
                this.axios.get('getimgcategory')
                    .then(response => {
                        if (response.data.status === 0) {
                            //手动拼接商品列表
                            response.data.message.unshift({title: '全部', id: 0});
                            this.category = response.data.message;
                        } else {
                            this.$toast('商品列表获取失败!')
                        }
                    })
            },
            getPhotoList(id) {
                //根据id获取图片
                this.axios.get(`getimages/${id}`)
                    .then(response => {
                        if (response.data.status === 0) {
                            //手动拼接商品列表
                            this.photoList = response.data.message;
                        } else {
                            this.$toast('添加评论信息失败!')
                        }
                    })
            }
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        }
    }
</script>

<style scoped>
    .mui-segmented-control.mui-scroll-wrapper .mui-scroll {
        font-size: 35px;
    }
    * {
        touch-action: pan-y;
    }
    .mui-segmented-control.mui-segmented-control-inverted .mui-control-item {
        margin: 0 20px;
    }
    .mui-slider {
        top: 25px;
        height: 70px;
    }
    .photoList {
        margin: 0;
        padding: 30px;
        padding-bottom: 0;
    }
    .photoList li {
        background-color: #ccc;
        text-align: center;
        list-style: none;
        margin-bottom: 20px;
        box-shadow: 0 0 20px #999;
        position: relative;
    }
    .photoList li img {
        height: 100%;
        width: 100%;
        vertical-align: center;
    }
    .photoList li img[lazy="loading"] {
        width: 40px;
        height: 300px;
        margin: auto;
    }
    .photoList li .info {
        color: white;
        text-align: left;
        position: absolute;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.4);
        max-height: 300px;
    }
    .body {
        font-weight: inherit;
    }
</style>